package com.marketlive.app.b2c.struts;

import javax.servlet.http.HttpServletRequest;


/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.apache.struts.action.*;
import com.marketlive.app.b2c.struts.security.SSLSupportDispatchAction;


/**
 * Abstract DispatchAction class for Actions that must provide a validate method.
 * The RequestProcessor is responsible for checking if the
 * action implements the interface and making the call.
 * Should use XmlValidatingDisplatchAction if validation can be performed
 * using the validator config file.
 *
 * User: emickelson
 * Date: Aug 19, 2005
 * Time: 3:05:52 PM
 *
 */
abstract public class ValidatingDispatchAction extends SSLSupportDispatchAction implements ValidatingAction {

	
	/**
	 * Convenience method for posting error messages with no arguments. 
	 * @param errorKey Message key from resource file.
	 * @param request
	 */
	protected void postGlobalError(String errorKey, HttpServletRequest request) {
		postGlobalError(errorKey, null, request);
	}
	
	/**
	 * Convenience method for posting error messages with zero or one argument. 
	 * @param errorKey Message key from resource file.
	 * @param arg Single argument for message.  Not used if null.
	 * @param request
	 */
	protected void postGlobalError(String errorKey, Object arg, HttpServletRequest request) {
		ActionMessage msg = (arg == null ? 
		                     new ActionMessage(errorKey) : 
                             new ActionMessage(errorKey, arg));
		ActionMessages errors = new ActionErrors();
		errors.add(ActionMessages.GLOBAL_MESSAGE, msg);
		saveErrors(request, (ActionMessages)errors);
	}



}
